package com.match;

/**
 * Created by TimeLiar on 2015/9/22.
 *
 */
public class SqlParse {
    private String sqlString;
    private String[] afterArray;

    public SqlParse(){}
    public SqlParse(String sqlString) {
        this.sqlString = sqlString;
    }

    private void before() {
        sqlString = sqlString.trim();
        sqlString = sqlString.toLowerCase();
        sqlString = sqlString.replaceAll(";", "");
        afterArray = sqlString.split(" ");
    }

    public void parse() throws com.util.Error {
        before();
        SqlFunctions functions = new SqlFunctions();
        switch (afterArray[0]){
            case "select":functions.select(sqlString);break;
            case "update":functions.update(sqlString);break;
            case "create":functions.create(sqlString);break;
            case "delete":functions.delete(sqlString);break;
            case "insert":functions.insert(sqlString);break;
            case "alter":functions.alter(sqlString);break;
            case "desc":functions.desc(sqlString);break;
            case "drop":functions.drop(sqlString);break;
            case "source":functions.source(sqlString);break;
            case "truncate":functions.truncate(sqlString);break;
            case "show":functions.show(sqlString);break;
            case "check":functions.check(sqlString);break;
            default:throw new com.util.Error(afterArray,0,"unknown");
        }
    }

    public void setSqlString(String sqlString) {
        this.sqlString = sqlString;
    }
}
